﻿//#define MACHINE_X86

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace Inovance_GR10_2HCE_UserCtrl
{
    public class GR10_2HCE_UserCtrl
    {
        #region STATIC
#if MACHINE_X86
        public const string EtherCATConfigApiDllName = "GR10-2HCE-UserCtrl_x86.dll";
#else
        public const string EtherCATConfigApiDllName = "GR10-2HCE-UserCtrl_x64.dll";
#endif
        #endregion


                 ///*==========================================================================*/
        ///*----             FUNCTION DEFINE                                       ---*/
        ///*==========================================================================*/

        ///*==========================================================================*/
        ///*----1.1.1 位置比较输出功能                               ---*/
        ///*==========================================================================*/
        [DllImport(EtherCATConfigApiDllName, EntryPoint = "IMC_2HCE_CompareOutConfig", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
                 public static extern UInt32 IMC_2HCE_CompareOutConfig(UInt64 cardHandle, Int16 station_id, short chanel, short portNo, int countdata, short pulsewidth);

        [DllImport(EtherCATConfigApiDllName, EntryPoint = "IMC_2HCE_StartCompareOut", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
        public static extern UInt32 IMC_2HCE_StartCompareOut(UInt64 cardHandle, Int16 station_id, short chanel, short portNo);

        [DllImport(EtherCATConfigApiDllName, EntryPoint = "IMC_2HCE_StopCompareOut", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
        public static extern UInt32 IMC_2HCE_StopCompareOut(UInt64 cardHandle, Int16 station_id, short chanel, short portNo);

        [DllImport(EtherCATConfigApiDllName, EntryPoint = "IMC_2HCE_GetCompareSts", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
        public static extern UInt32 IMC_2HCE_GetCompareSts(UInt64 cardHandle, Int16 station_id, short chanel, short portNo, ref short pEnableSts, ref short pCmpSts, ref short pErrSts);

        [DllImport(EtherCATConfigApiDllName, EntryPoint = "IMC_2HCE_ClearCompareOutSts", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
        public static extern UInt32 IMC_2HCE_ClearCompareOutSts(UInt64 cardHandle, Int16 station_id, short chanel, short portNo);
        /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
        /*----			1.1.2 通用输入输出                             ---*/
        /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
        [DllImport(EtherCATConfigApiDllName, EntryPoint = "IMC_2HCE_GetInput", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
        public static extern UInt32 IMC_2HCE_GetInput(UInt64 cardHandle, Int16 station_id, short chanel, ref short pValue);

          [DllImport(EtherCATConfigApiDllName, EntryPoint = "IMC_2HCE_GetOutput", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
        public static extern UInt32 IMC_2HCE_GetOutput(UInt64 cardHandle, Int16 station_id, short chanel, ref short pValue);

          [DllImport(EtherCATConfigApiDllName, EntryPoint = "IMC_2HCE_SetOutput", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
          public static extern UInt32 IMC_2HCE_SetOutput(UInt64 cardHandle, Int16 station_id, short chanel, short bitNo, short pValue);


        /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
        /*----			1.1.3 计数器功能                                  ---*/
        /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
        [DllImport(EtherCATConfigApiDllName, EntryPoint = "IMC_2HCE_CounterConfig", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
          public static extern UInt32 IMC_2HCE_CounterConfig(UInt64 cardHandle, Int16 station_id, short chanel, short mode, short dir, short type);

        [DllImport(EtherCATConfigApiDllName, EntryPoint = "IMC_2HCE_StartCounter", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
        public static extern UInt32 IMC_2HCE_StartCounter(UInt64 cardHandle, Int16 station_id, short chanel);

        [DllImport(EtherCATConfigApiDllName, EntryPoint = "IMC_2HCE_StopCounter", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
        public static extern UInt32 IMC_2HCE_StopCounter(UInt64 cardHandle, Int16 station_id, short chanel);

        [DllImport(EtherCATConfigApiDllName, EntryPoint = "IMC_2HCE_ClearCounter", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
        public static extern UInt32 IMC_2HCE_ClearCounter(UInt64 cardHandle, Int16 station_id, short chanel);

        [DllImport(EtherCATConfigApiDllName, EntryPoint = "IMC_2HCE_GetCounterSts", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
        public static extern UInt32 IMC_2HCE_GetCounterSts(UInt64 cardHandle, Int16 station_id, short chanel, ref short CounterSts, ref Int32 pValue);

        [DllImport(EtherCATConfigApiDllName, EntryPoint = "IMC_2HCE_PresetCounter", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
        public static extern UInt32 IMC_2HCE_PresetCounter(UInt64 cardHandle, Int16 station_id, short chanel, Int32 pValue);

        [DllImport(EtherCATConfigApiDllName, EntryPoint = "IMC_2HCE_Test", ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
        public static extern UInt32 IMC_2HCE_Test();
  
    }
}
